package com.webzavod.json;

import com.webzavod.model.Book;
import com.webzavod.model.Order;
import com.webzavod.model.User;

import javax.persistence.*;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: v.tsapaev
 * Date: 25.05.12
 * Time: 18:44
 * To change this template use File | Settings | File Templates.
 */

/**
 * Class help to transfer info from UI to server
 */
public class OrderJSON {

    private Integer orderId;

    private List<Book> bookList;

    private User owner;

    public OrderJSON(){}

    public OrderJSON(Order order){
        this();
        orderId = order.getOrderId();
        owner = order.getOwner();
        bookList = new ArrayList<Book>();
        Map<Book, Integer> bookMap = order.getBookMap();
        for (Map.Entry<Book, Integer> entry: bookMap.entrySet()){
            for (int i = 0; i < entry.getValue(); i++){
                bookList.add(entry.getKey());
            }
        }
    }

    public Integer getOrderId() {
        return orderId;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public List<Book> getBookList() {
        return bookList;
    }

    public void setBookList(List<Book> bookList) {
        this.bookList = bookList;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    @Override
    public String toString() {
        return "Order{" +
                "orderId=" + orderId +
                ", bookList=" + bookList +
                ", owner=" + owner +
                '}';
    }
}
